package com.pzhu.model.entity;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.pzhu.model.help.BaseEntity;
import com.pzhu.model.help.CustomDateTimeSerializer;
import lombok.*;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

/**
 * 用户表
 * @TableName hs_user
 */
@Data
@TableName(value ="hs_user")
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class User extends BaseEntity implements Serializable {

    /**
     * 用户名
     */
    @TableField(value = "username")
    @NotBlank(message = "用户名不能为空！")
    private String username;

    /**
     * 微信登录的openid
     */
    @TableField(value = "open_id")
    private String openId;

    /**
     * 密码
     */
    @TableField(value = "password")
    @NotBlank(message = "密码不能为空！")
    @Size(min = 6,max = 8,message = "密码长度必须在6~8之间")
    private String password;

    /**
     * 用户头像
     */
    @TableField(value = "avatar")
    private String avatar = "default.jpg";

    /**
     * 性别
     */
    @TableField(value = "gender")
    private String gender;

    /**
     * 用户邮箱
     */
    @TableField(value = "email")
    @NotBlank(message = "邮箱不能为空！")
    @Email(message = "邮箱格式不正确")
    private String email;

    /**
     * 手机号码
     */
    @TableField(value = "phone")
    @NotBlank(message = "手机号码不能为空！")
    private String phone;

    /**
     * 地址
     */
    @TableField(value = "address")
    private String address;

    /**
     * 最后登录时间
     */
    @TableField(value = "login_date")
    @JsonSerialize(using= CustomDateTimeSerializer.class)
    @JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss")
    private Date loginDate;

    /**
     * 帐号状态（0正常 1停用）
     */
    @TableField(value = "status")
    private String status;

    /**
     * 角色（0-管理员 1-服务人员 2-普通用户）
     */
    @TableField(value = "role")
    private Integer role;

    /**
     * 删除标记
     */
    @TableLogic
    @TableField(value = "is_deleted")
    private Integer isDeleted;


    /**
     * 所属角色
     */
    @TableField(exist = false)
    private String roles;

    /**
     * 所有角色集合
     */
    @TableField(exist = false)
    private List<Role> roleList;

    /**
     * 确认新密码
     */
    @TableField(exist = false)
    private String newPassword;


    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}